Passed
Push — master ( fc2d57...76a657 )
by Barry
01:39
created

helpers.js ➔ _findFencedCode   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 79
rs 8.8701
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
2
export function earlierOf (a, b) {
3
  // inspects the .start property of a and b and returns the one
4
  // with the lowest start position
5
  if (b.start !== -1 && (a.start === -1 || b.start < a.start)) {
6
    return b
7
  } else {
8
    return a
9
  }
10
}
11
12
export function replaceLineEndings (txt, CRLF) {
13
  // replaces line endings within txt, with CRLF if CRLF is true, otherwise just LF
14
  if (CRLF === true) {
15
    // NB can't do the replacement of '\n' with '\r\n' using regex due to javascript limitations
16
    let p = 0 // current position in the string
17
    let x = 0 // location of '\n' in the string
18
    let t = '' // output string
19
    while (true) {
20
      x = txt.indexOf('\n', p)
21
      if (x === -1) {
22
        // we've not got any more '\n' in the string so complete and exit
23
        t = t + txt.substr(p)
24
        return t
25
      } else if (x === 0 || txt.substr(x - 1, 1) !== '\r') {
26
        t = t + txt.substring(p, x) + '\r\n'
27
        p = x + 1
28
      } else {
29
        t = t + txt.substring(p, x + 1)
30
        p = x + 1
31
      }
32
    }
33
  } else {
34
    return txt.replace(/(\r\n)/g, '\n')
35
  }
36
}
37